/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-09-02 22:42:44
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-09-03 22:51:26
 * @FilePath: /metaverse-manage/app/service/Manager.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Service } from 'egg';

export default class ManagerService extends Service {
  async queryAllManagers() {
    const result = await this.app.mysql.query('select id, username from sys_manager');
    return result;
  }

  async queryManagerById(id: number) {
    const result = await this.app.mysql.query(`select id, username from sys_manager where id = '${id}'`);
    // const result = await this.app.mysql.get('sys_manager', { id });
    return result[0];
  }

  async createManager(manager) {
    const result = await this.app.mysql.insert('sys_manager', manager);
    return result;
  }

  async updateManager(id, manager) {
    const result = await this.app.mysql.update('sys_manager', manager, {
      where: { id },
    });
    return result;
  }
  async removeManager(id: number) {
    const result = await this.app.mysql.delete('sys_manager', { id });
    return result;
  }

  async login(userName: string, password: string) {
    const result = await this.app.mysql.query(`select id, username from sys_manager where username='${userName}' and password='${password}'`);
    return result[0];
  }


}
